package cn.wgx.module.sys.service;

import cn.wgx.common.base.IBaseService;
import cn.wgx.common.entity.ent.EntApp;
import cn.wgx.common.entity.ent.EntUserApp;
import cn.wgx.common.entity.ent.Enterprise;
import cn.wgx.common.entity.sys.SysApp;
import cn.wgx.module.ent.service.EntAppService;
import cn.wgx.module.ent.service.EntUserAppService;
import cn.wgx.module.ent.service.EnterpriseService;
import cn.wgx.module.sys.mapper.AppMapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

@Service
public class AppService extends IBaseService<AppMapper, SysApp> {

    @Autowired
    EntAppService entAppService;
    @Autowired
    EntUserAppService entUserAppService;

    public List<Enterprise> getEntNotInApp(Page<Enterprise> page, Integer app_id) {
        Page<Enterprise> page1 = baseMapper.listEntNotInApp(page, app_id);
        return page1.getRecords();
    }

    @Override
    public boolean removeById(Serializable id) {
        //如果删除应用，默认删除所有
        QueryWrapper<EntApp> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("app_id", id);
        entAppService.remove(queryWrapper);
        QueryWrapper<EntUserApp> queryWrapper1 = new QueryWrapper<>();
        queryWrapper.eq("app_id", id);
        entUserAppService.remove(queryWrapper1);
        return true;
    }
}
